package com.converters;


import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class DefaultConverters {
    private static final Map<String, Converter> DEFAULT_CONVERTERS = new ConcurrentHashMap();

    public DefaultConverters() {
    }

    public static Converter getConverter(String className) {
        Converter converter = DEFAULT_CONVERTERS.get(className);
        if (converter == null) {
            try {
                Class<?> clazz = Class.forName(className);
                Converter c = (Converter)clazz.newInstance();
                DEFAULT_CONVERTERS.put(className, c);
                return c;
            } catch (ClassNotFoundException var4) {
                throw new IllegalArgumentException("找不到对应的转换器类", var4);
            } catch (InstantiationException | IllegalAccessException var5) {
                throw new IllegalArgumentException("转换器必须提供无参构造器", var5);
            }
        } else {
            return converter;
        }
    }

    static {
        DEFAULT_CONVERTERS.put(AutoConverter.class.getName(), new AutoConverter());
        DEFAULT_CONVERTERS.put(StringConverter.class.getName(), new com.converters.StringConverter());
        DEFAULT_CONVERTERS.put(ListConverter.class.getName(), new ListConverter());
    }
}
